import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.Pane;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.stage.Stage;

public class homework_02 extends Application {

    @Override
    public void start(Stage primaryStage) {
        Pane root = new Pane();
        Group group = new Group();

        // 创建太阳的径向渐变
        RadialGradient gradient = new RadialGradient(
                0, 0, 0.5, 0.5, 0.5, true, CycleMethod.NO_CYCLE,
                new Stop(0, Color.ORANGE),
                new Stop(1, Color.RED)
        );

        // 创建太阳
        Circle sun = new Circle(200, 100, 50);
        // 使用径向渐变填充太阳
        sun.setFill(gradient);
        DropShadow sunShadow = new DropShadow();
        sunShadow.setRadius(10.0);
        sunShadow.setColor(Color.YELLOW);
        sun.setEffect(sunShadow);

        // 创建太阳光芒
        for (int i = 0; i < 12; i++) {
            double angle = Math.toRadians(i * 30);
            double x = 200 + 50 * Math.cos(angle);
            double y = 100 + 50 * Math.sin(angle);
            Circle ray = new Circle(x, y, 10);
            ray.setFill(Color.YELLOW);
            group.getChildren().add(ray);
        }

        // 创建云朵
        Path cloud1 = createCloud(100, 200);
        Path cloud2 = createCloud(300, 250);

        // 创建海水
        Rectangle sea = createSea();
        // 创建波浪线
        Path wave1 = createWave(0, 300);
        Path wave2 = createWave(200, 305);

        group.getChildren().addAll(sun, cloud1, cloud2, sea, wave1, wave2);
        root.getChildren().add(group);

        // 设置背景颜色
        root.setStyle("-fx-background-color: LIGHTSKYBLUE;");

        Scene scene = new Scene(root, 400, 400);
        primaryStage.setTitle("Solar Scene");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private Path createCloud(double x, double y) {
        Path cloud = new Path();
        cloud.setTranslateX(x);
        cloud.setTranslateY(y);
        cloud.setFill(Color.WHITE);
        cloud.setStroke(Color.LIGHTGRAY);
        cloud.setStrokeWidth(2);

        cloud.getElements().addAll(
                new MoveTo(0, 20),
                new QuadCurveTo(20, 0, 40, 20),
                new QuadCurveTo(50, 30, 40, 40),
                new QuadCurveTo(20, 50, 0, 40),
                new QuadCurveTo(-10, 30, 0, 20)
        );
        return cloud;
    }

    private Rectangle createSea() {
        // 创建海水的渐变
        LinearGradient seaGradient = new LinearGradient(
                0, 0, 0, 1, true, CycleMethod.NO_CYCLE,
                new Stop(0, Color.rgb(0, 128, 255, 0.8)),
                new Stop(1, Color.rgb(0, 64, 128, 0.8))
        );
        Rectangle sea = new Rectangle(0, 300, 400, 100);
        sea.setFill(seaGradient);
        return sea;
    }

    private Path createWave(double x, double y) {
        Path wave = new Path();
        wave.setTranslateX(x);
        wave.setTranslateY(y);
        wave.setStroke(Color.rgb(0, 128, 255, 0.8));
        wave.setStrokeWidth(2);
        wave.setFill(null);

        for (int i = 0; i < 4; i++) {
            if (i == 0) {
                wave.getElements().add(new MoveTo(0, 0));
            }
            wave.getElements().add(new QuadCurveTo(50, -10, 100, 0));
        }
        return wave;
    }

    public static void main(String[] args) {
        launch(args);
    }
}